package com.study.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.study.bean.HostBean;
import com.study.service.impl.FindImgServicce;
import com.study.tools.MyTools;

/**
 * Servlet implementation class FinfImgControl
 */
@WebServlet("/FinfImgControl")
public class FinfImgControl extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		 request.setCharacterEncoding("utf-8");
		 response.setCharacterEncoding("utf-8");
		 HostBean hostbean= new HostBean();
		  String hostid= request.getSession().getAttribute("Host_id").toString();
		  System.out.println("hostid:"+hostid);
		  hostbean.setHost_id(new Integer(hostid));
		  List<HostBean> list=MyTools.getInstance(FindImgServicce.class).jsonOfQuery(hostbean);
		  System.out.println("listP:"+list);
		  ///借助第三方插件，降级和转换为json字符串
		  //list---->json
		  String strjson=JSON.toJSONStringWithDateFormat(list, "yyyy-MM-dd");
		  //ajax相应
		 PrintWriter pw=response.getWriter();
		 //将json发回到客户端跨浏览器
		 pw.write(strjson);
		 pw.flush();
		 pw.close();
	}

	
}
